//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __SHARE_MEM_CONVERT_H__
#define __SHARE_MEM_CONVERT_H__

#if defined(_win32) && defined(_pc)

EXTERN_C ECode __cdecl OpenShareMem(unsigned long id, Address *pShareAddr);
EXTERN_C ECode __cdecl FreeOpenShareMem(Address ShareAddr);
EXTERN_C ECode __cdecl AllocShareMem(MemorySize size,
                                    MemoryProtection protection,
                                    Address *pShareAddr,
                                    unsigned long *pId);
EXTERN_C ECode __cdecl FreeAllocShareMem(Address ShareAddr);
EXTERN_C ECode __cdecl ConvertAllocAddrToId(Address ShareAddr,
                                unsigned long offset,
                                unsigned long *pId);

#define ConvertIdToAddr(BufferInformationArry, count) \
            do{ \
                BufferInformationArry.SetUsed(count);\
                for(int i = 0; i < count; i++){\
                    OpenShareMem((UInt32)BufferInformationArry[i].addr, &BufferInformationArry[i].addr);\
                }\
            }while(0)

#define FreeShareMem(BufferInformationArry, count) \
            do{ \
                for(int i = 0; i < count; i++){\
                    FreeOpenShareMem((UInt32)BufferInformationArry[i].addr);\
                }\
            }while(0)
#endif
#endif//__SHARE_MEM_CONVERT_H__
